/*
 * WispCharacter.java
 *
 * Created on January 4, 2008, 11:23 Am
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package wispappautogeneration;
import java.sql.*;
import java.io.*;
import java.util.*;
//import java.util.StringTokenizer;
import java.lang.Exception.*;
/**
 *
 * @author Nezie Santos
 */
public class WispCharacter {
    private dbConnection dbcon = new dbConnection();
    private int cHP, mHP, cMP, mMP, healPt;
    private double dPoint;
     private String charactername;

    public int getCHP() {
        return cHP;
    }

    public void setCHP(int cHP) {
        this.cHP = cHP;
    }


    public int getMHP() {
        return mHP;
    }

    public void setMHP(int mHP) {
        this.mHP = mHP;
    }


    public int getCMP() {
        return cMP;
    }

    public void setCMP(int cMP) {
        this.cMP = cMP;
    }


    public int getMMP() {
        return mMP;
    }

    public void setMMP(int mMP) {
        this.mMP = mMP;
    }


    public int getHealPt() {
        return healPt;
    }

    public void setHealPt(int healPt) {
        this.healPt = healPt;
    }

    
    public double getDPoint() {
        return dPoint;
    }

    public void setDPoint(double dPoint) {
        this.dPoint = dPoint;
    }
    
     public Vector viewAllCharacters (){
        //Statement stmt;
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        Vector<WispCharacter> cList;
            
        cList = new Vector<WispCharacter>();
        Iterator it = cList.iterator();
                
        getDbcon().connect();
        query = "SELECT healPt, currentHP, maxHP, currentMP, maxMP, deedPt, characterName FROM WispCharacter";
        
        try
        {
          
             	
            stmt = getDbcon().con.prepareStatement(query);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                WispCharacter w = new WispCharacter();
                w.healPt = rs.getInt("healPt");
                w.setCHP(rs.getInt("currentHP"));
                w.setMHP(rs.getInt("maxHP")); 
                w.setCMP(rs.getInt("currentMP"));
                w.setMMP(rs.getInt("maxMP"));
                w.setDPoint(rs.getDouble("deedPt"));
                w.setCharactername(rs.getString("characterName"));
                cList.add(w);
             }
            //crset.populate(rs);
            rs.close(); 					
            stmt.close();
            return cList;
 				
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
       finally {
            getDbcon().disconnect();
        }
        return null;
     }
     
      public void editCharInfo (WispCharacter wc) {
         						
        String query; 					
        ResultSet rs;
        PreparedStatement stmt;

        getDbcon().connect();
       
            query = "UPDATE WispCharacter SET healPt = ?, currentHP = ?, currentMP = ?, deedPt = ? WHERE characterName = ?";
        
        try 
        {
            stmt = getDbcon().con.prepareStatement(query);
            if (wc.healPt + 1 > 3)
                stmt.setInt(1, 3);
            else
                stmt.setInt(1, wc.healPt+1);
            if (wc.cHP+1 > wc.mHP)
                stmt.setInt(2, wc.mHP);
            else
                stmt.setInt(2, wc.cHP+1);
            if (wc.cMP+1 > wc.mMP)
                stmt.setInt(3, wc.mMP);
            else
                stmt.setInt(3, wc.cMP+1);
            if (wc.dPoint+10 > 200)
                stmt.setDouble(4, 200); 
            else
                stmt.setDouble(4, wc.dPoint+10); 
            stmt.setString(5, wc.charactername);
            stmt.executeUpdate();	
            stmt.close();
        } catch (Exception ex) 
        {
            System.out.println(ex.getMessage());	       	
        }
        getDbcon().disconnect();
     }

    public dbConnection getDbcon() {
        return dbcon;
    }

    public void setDbcon(dbConnection dbcon) {
        this.dbcon = dbcon;
    }

    public String getCharactername() {
        return charactername;
    }

    public void setCharactername(String charactername) {
        this.charactername = charactername;
    }
}
